﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Threading;

namespace OnlineDovizOtomasyonu
{
    public partial class caritanimla : System.Web.UI.Page
    {
        Fonksiyon Sistem = new Fonksiyon();
        Mesaj Mesaj = new Mesaj();
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (Page.IsPostBack == false)
            //{
                CariNumara();
                SehirCek();
            //}
        }

        void CariNumara()
        {
            int KayitSayisi = 0;
            SqlConnection Mycon = Sistem.baglan();
            SqlDataAdapter MyAdp = new SqlDataAdapter("Select * From WEBINGDOVIZ_TBLCARI", Mycon);
            DataTable MyTable = new DataTable();
            MyAdp.Fill(MyTable);
            KayitSayisi = MyTable.Rows.Count;
            if (KayitSayisi <= 0)
            {
                txtMusteriNo.Text = DateTime.Now.Year + "-1";
            }
            else
            {
                int YeniSayi = Convert.ToInt32(MyTable.Rows.Count) + 1;
                txtMusteriNo.Text = DateTime.Now.Year + "-" + YeniSayi;
            }



        }

        void SehirCek()
        {
            txtSehir.Items.Clear();
            DataTable Sehirler = Sistem.GetDataTable("Select * From TBLIL ORDER BY ID");
            for (int i = 0; i < Sehirler.Rows.Count; i++)
            {
                DataRow Sehir = Sehirler.Rows[i];
                txtSehir.Items.Add(Sehir["SEHIR"].ToString());
                txtSehir.Items[i].Value = Sehir["KOD"].ToString();
            }
        }

        void IlceCek(int Sehir)
        {
            txtIlce.Items.Clear();
            DataTable Ilceler = Sistem.GetDataTable("Select * From TBLILCE WHERE SEHIR=" + Sehir + " ORDER BY ID");
            for (int i = 0; i < Ilceler.Rows.Count; i++)
            {
                DataRow Ilce = Ilceler.Rows[i];
                txtIlce.Items.Add(Ilce["ILCE"].ToString());
                txtIlce.Items[i].Value = Ilce["ID"].ToString();
            }
        }

        void GroupCek()
        {
            txtMusteriGroup.Items.Clear();
            DataTable Sehirler = Sistem.GetDataTable("Select * From WEBINGDOVIZ_TBLGROUP ORDER BY ID");
            for (int i = 0; i < Sehirler.Rows.Count; i++)
            {
                DataRow Sehir = Sehirler.Rows[i];
                txtMusteriGroup.Items.Add(Sehir["ADI"].ToString());
                txtMusteriGroup.Items[i].Value = Sehir["ID"].ToString();
            }
        }

        protected void txtIl_SelectedIndexChanged(object sender, EventArgs e)
        {
            IlceCek(Convert.ToInt32(txtSehir.Value));
        }

        protected void btnKaydet_Click(object sender, EventArgs e)
        {
            //try
            //{
                Kaydet();
                Response.Redirect("caritanimla.aspx");
            //}
            //catch (System.Exception ex)
            //{
            //    //Mesaj.Show("İşleminiz Gerçekleştirilmedi!\nBilgileri Kontrol Ederek Tekrar Deneyiniz.\nHata Ayrıntısı:\n");
            //}
        }

        protected void btnTemizle_Click(object sender, EventArgs e)
        {
            Response.Redirect("caritanimla.aspx");
        }

        void Kaydet()
        {
            SqlConnection baglanti = Sistem.baglan();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = baglanti;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "SP_WEBINGDOVIZ_CARI_EKLE";
            cmd.Parameters.Add("KODU", txtMusteriNo.Text);
            cmd.Parameters.Add("ADI", txtMusteriAdi.Text);
            cmd.Parameters.Add("GRUP", txtMusteriGroup.Value);
            cmd.Parameters.Add("DURUM", txtDurum.Value);
            cmd.Parameters.Add("ADRES", txtAdres.Text);
            cmd.Parameters.Add("IL", txtSehir.Text);
            cmd.Parameters.Add("ILCE", txtIlce.Text);
            cmd.Parameters.Add("POSTAKODU", txtPostaKodu.Text);
            cmd.Parameters.Add("WEB", txtWebAdresi.Text);
            cmd.Parameters.Add("MAIL", txtMailAdresi.Text);
            cmd.Parameters.Add("TEL1", txtTel1.Text);
            cmd.Parameters.Add("TEL2", txtTel2.Text);
            cmd.Parameters.Add("CEP1", txtCep1.Text);
            cmd.Parameters.Add("CEP2", txtCep2.Text);
            cmd.Parameters.Add("FAKS", txtFaks.Text);
            cmd.Parameters.Add("TC", txtTC.Text);
            cmd.Parameters.Add("VERGINO", txtVergiNo.Text);
            cmd.Parameters.Add("VERGIDAIRESI", txtVergiDairesi.Text);
            cmd.Parameters.Add("SUBE1", txtSube1.Text);
            cmd.Parameters.Add("BANKA1", txtBanka1.Text);
            cmd.Parameters.Add("HESAP1", txtHesapNo1.Text);
            cmd.Parameters.Add("IBAN1", txtIban1.Text);
            cmd.Parameters.Add("SUBE2", txtSube2.Text);
            cmd.Parameters.Add("BANKA2", txtBanka2.Text);
            cmd.Parameters.Add("HESAP2", txtHesapNo2.Text);
            cmd.Parameters.Add("IBAN2", txtIban2.Text);
            cmd.Parameters.Add("SUBE3", txtSube3.Text);
            cmd.Parameters.Add("BANKA3", txtBanka3.Text);
            cmd.Parameters.Add("HESAP3", txtHesapNo3.Text);
            cmd.Parameters.Add("IBAN3", txtIban3.Text);
            cmd.Parameters.Add("SUBE4", txtSube4.Text);
            cmd.Parameters.Add("BANKA4", txtBanka4.Text);
            cmd.Parameters.Add("HESAP4", txtHesapNo4.Text);
            cmd.Parameters.Add("IBAN4", txtIban4.Text);
            cmd.ExecuteNonQuery();
            //Response.Redirect("musterigrouptanimla.aspx");
        }
    }
}